package com.nathan.mq.integration.vender.activemq.receive;

import com.nathan.mq.integration.constant.MQVenderCS;
import com.nathan.mq.integration.model.BroadcastMqModel;
import com.nathan.mq.integration.service.IMQMsgReceiver;
import com.nathan.mq.integration.vender.activemq.ActiveMQConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * activeMQ消息接收器：仅在vender=activeMQ时 && 项目实现IMQReceiver接口时 进行实例化 业务：  更新系统配置参数
 *
 * @Description:
 * @Author: zhujunjie
 * @Date: 2021/12/9 17:20
 */
@Component
@ConditionalOnProperty(name = MQVenderCS.YML_VENDER_KEY, havingValue = MQVenderCS.ACTIVE_MQ)
@ConditionalOnBean(BroadcastMqModel.IMQReceiver.class)
public class BroadcastActiveMQReceiver implements IMQMsgReceiver {

    @Autowired
    private BroadcastMqModel.IMQReceiver mqReceiver;

    /**
     * 接收 【 MQSendTypeEnum.BROADCAST  】 广播类型的消息
     **/
    @Override
    @JmsListener(destination = BroadcastMqModel.MQ_NAME, containerFactory = ActiveMQConfig.TOPIC_LISTENER_CONTAINER)
    public void receiveMsg(String msg) {
        mqReceiver.receive(BroadcastMqModel.parse(msg));
    }

}
